/* exittest.c
 *	Test for part 2 implementation
 *	
 */
#include "syscall.h"

void ExitTest();
void ExitOne();
void ExitTwo();
void ExitThree();
void ExitFour();
void ExitFive();
void ExitSix();
void ExitSeven();
void ExitEight();
void ExitNine();

int printLock;

int main(int argc, char **argv)
{
	printLock = CreateLock();

	ExitTest();
}

void ExitOne()
{
	PrintOut("Successfully forked 1 now trying to exit\n",41);
	Exit(2);
}

void ExitTwo()
{
	PrintOut("Successfully forked 2 now trying to exit\n",41);
	Exit(2);
}

void ExitThree()
{
	PrintOut("Successfully forked 3 now trying to exit\n",41);
	Exit(2);
}

void ExitFour()
{
	PrintOut("Successfully forked 4 now trying to exit with bad parameter Exit(0)\n",68);
	Exit(0);
}

void ExitFive()
{
	PrintOut("Successfully forked 5 now trying to exit with bad parameter Exit(1)\n",68);
	Exit(1);
}

void ExitSix()
{
	PrintOut("Successfully forked 6 now trying to exit with bad parameter Exit(1)\n",68);
	Exit(1);
}

void ExitSeven()
{


}

void ExitEight()
{


}


void ExitNine()
{



}

void ExitTest()
{
	void (*exitTestOne)(void);
	void (*exitTestTwo)(void);
	void (*exitTestThree)(void);
	void (*exitTestFour)(void);
	void (*exitTestFive)(void);
	void (*exitTestSix)(void);
	void (*exitTestSeven)(void);
	void (*exitTestEight)(void);
	void (*exitTestNine)(void);
	
	exitTestOne = &ExitOne;
	exitTestTwo = &ExitTwo;
	exitTestThree = &ExitThree;
	exitTestFour = &ExitFour;
	exitTestFive = &ExitFive;
	exitTestSix = &ExitSix;
	exitTestSeven = &ExitSeven;
	exitTestEight = &ExitEight;
	exitTestNine = &ExitNine;

	PrintOut("Test One - Forking function and immediately exiting thread\n\n",60);
	
	Fork(exitTestOne);
	Fork(exitTestTwo);
	Fork(exitTestThree);
	Fork(exitTestOne);
	Fork(exitTestTwo);
	Fork(exitTestThree);
	Fork(exitTestOne);
	Fork(exitTestTwo);
	Fork(exitTestThree);

	Acquire(printLock,0);
	PrintOut("Test One - Successful\n\n", 23);
	Release(printLock,0);

	Acquire(printLock,0);
	PrintOut("Test Two - Bad Exit(int) parameters\n\n",37);
	Release(printLock,0);


	Fork(exitTestFour);
	Fork(exitTestFive);
	Fork(exitTestSix);
	Fork(exitTestFour);
	Fork(exitTestFive);
	Fork(exitTestSix);

	Acquire(printLock,0);
	PrintOut("Test Two - Successful\n\n", 23);
	Release(printLock,0);

	Acquire(printLock,0);
	PrintOut("Now trying to kill process with bad parameter Exit(-1)\n",55);
	Acquire(printLock,0);

	Exit(-1);

	
	/*PrintOut("Exit failed if this is displayed\n",34);*/
}
